$(function() {
	$('#huodg').datagrid({
		//请求地址
	    url:'../check/getcheckFrequency',
	    columns:[[
	    	{field:'',title:'',checkbox:true},
			{field:'frequencyId',title:'班次编号',width:'8%'},
			{field:'frequencyName',title:'班次名称',width:'8%'},
			{field:'category',title:'类别',width:'8%'},
			{field:'remark',title:'备注',width:'15%'},
			{field:'systemUse',title:'系统',width:'5%',disabled:true,
				formatter : function(value, row, index) {
					if (row.systemUse === 'true') {
						var btn = " <input type='checkbox' checked=true>";
						return btn;
					} else if (row.systemUse === 'false') {
					    var btn = " <input type='checkbox' />";
						return btn;
					}
				}
			},
			{field:'maker',title:'创建者',width:'8%'},
			{field:'makeTime',title:'创建日期',width:'15%'},
			{field:'updateEmp',title:'修改者',width:'8%'},
			{field:'updateTime',title:'修改日期',width:'15%'},
			{field:'state',title:'状态',width:'5%',
				formatter : function(value, row, index) {
					if (row.state==='是') {
					var btns = "<a href='#' name='operaf' class='easyui-linkbutton'></a>";
					return btns;
					}
				}
			} ] ],
			onLoadSuccess : function() {
				$("a[name='operaf']").linkbutton({
					plain : true,
					iconCls : 'icon-edit',
				});
				$("a[name='operaf']").bind('click',function(){
					var rows = $('#huodg').datagrid('getSelected');
					$("#frequencyId").val(rows.frequencyId);
					$("#frequencyName").val(rows.frequencyName);
					$("#category").val(rows.category);
					$("#remark").val(rows.remark);
					$("#systemUse").attr("checked",rows.systemUse);
					$("#maker").val(rows.maker);
					$("#makeTime").val(rows.makeTime);
					$("#huodd").window("open");
				})
		},
		onLoadError:function(data){
			alert(1234)
		},
	    width:'100%',
	    fit:true,
	    //fit:true
	    fitColumns:true,
	    //隔行变色
	    striped:true,
	    nowrap:true,
	    //显示行号
	    rownumbers:true,
	    //设置单选
	    singleSelect:true,
		toolbar:'#huotb',
		//显示分页栏
		pagination:true,
		//设置每页大小
		pageSize:5,
		//可选的每页大小
		pageList:[5,10,20,50]
	});
});
 function searchname(value){
	 $('#huodg').datagrid('load','../check/serchcheckFrequency?frequencyName='+value);
} 
 
 
 var editIndex = undefined;
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($('#huodg').datagrid('validateRow', editIndex)){
			$('#huodg').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}
	function onClickCell(index, field){
		if (editIndex != index){
			if (endEditing()){
				$('#huodg').datagrid('selectRow', index)
						.datagrid('beginEdit', index);
				var ed = $('#huodg').datagrid('getEditor', {index:index,field:field});
				if (ed){
					($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
				}
				editIndex = index;
			} else {
				setTimeout(function(){
					$('#huodg').datagrid('selectRow', editIndex);
				},0);
			}
		}
	}
	function onEndEdit(index, row){
		var ed = $(this).datagrid('getEditor', {
			index: index,
			field: 'dname'
		});
		row.dname = $(ed.target).combobox('getText');
	}
	function append(){
		if (endEditing()){
			$('#huodg').datagrid('appendRow',{eid:'',ename:'',salary:'',did:''});
			editIndex = $('#huodg').datagrid('getRows').length-1;
			$('#huodg').datagrid('selectRow', editIndex)
					.datagrid('beginEdit', editIndex);
		}
	}
	function removeit(){
		if (editIndex == undefined){return}
		$('#huodg').datagrid('cancelEdit', editIndex)
				.datagrid('deleteRow', editIndex);
		editIndex = undefined;
	}
	function accept(){
		if (endEditing()){
			$('#huodg').datagrid('acceptChanges');
		}
	}
	function reject(){
		$('#huodg').datagrid('rejectChanges');
		editIndex = undefined;
	}
	function getChanges(){
		//var rows = $('#dg').datagrid('getChanges');
		//alert(JSON.stringify(rows));
		var inserted=$('#huodg').datagrid('getChanges','inserted');
		alert(JSON.stringify(inserted));
		
		var updated=$('#huodg').datagrid('getChanges','updated');
		alert(JSON.stringify(updated));
		
		var deleted=$('#huodg').datagrid('getChanges','deleted');
		alert(JSON.stringify(deleted));
	}
